//
//  NSDictionary+SLCategory.m
//  Objective-C
//
//  Created by S_Line on 2018/11/8.
//  Copyright © 2018 S_Line. All rights reserved.
//

#import "NSDictionary+SLCategory.h"

@implementation NSDictionary (SLCategory)

/**
 根据字典快速创建属性代码
 */
- (void)createPropertyCode {
    NSMutableString *propertyCode = [NSMutableString string];
    
    [self enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        NSString *code;
        if ([obj isKindOfClass:[NSString class]]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, copy) NSString *%@;", key];
        } else if ([obj isKindOfClass:[NSNumber class]]) {
            if ([obj isKindOfClass:NSClassFromString(@"__NSCFBoolean")]) {
                code = [NSString stringWithFormat:@"@property (nonatomic, assign) BOOL %@;", key];
            } else {
                code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSNumber *%@;", key];
            }
        } else if ([obj isKindOfClass:[NSArray class]]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSArray *%@;", key];
        } else if ([obj isKindOfClass:[NSDictionary class]]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@;", key];
        } else {
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) id %@;", key];
        }
        
        [propertyCode appendFormat:@"\n%@", code];
    }];
    
    NSLog(@"%@", propertyCode);
}

@end
